# -*- coding: utf-8 -*-
"""
AI写作接口调用函数
"""
import requests
import json

# url = "http://127.0.0.1:8000/writerapi/"

def useapi(url,desc,times=1,num=20):
    data = {}
    if desc:
        data['context'] = desc
    if times:
        data['times'] = int(times)
    if num:
        data['num'] = int(num)
    headers = {
        "Authorization": "Token dc820aa508a8df716a2646633f8e50bb91dd1f17",
        "Accept": "application/json, text/javascript, */*; q=0.01",
        "Accept-Language":"zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3",
        "Accept-Encoding": "gzip, deflate",
        "Content-Type":"application/x-www-form-urlencoded; charset=UTF-8",
        "X-Requested-With": "XMLHttpRequest",
        "Connection":"keep-alive",
        "Content-Length": "18",
        "charset":"UTF-8",
    }
    #一般登录注册页面均是post方式进行提交的，需要将post需要提交的数据（此处为需要发送验证码的手机号码）进行组装
    #初始化post请求对象（需要传入url、提交的数据、header）
    s = requests.get(url,data,headers=headers)
    #返回数据
    return json.loads(s.text)

# print(useapi(url,'今天很高兴'))